'use strict';

const NacosNamingClient = require('nacos').NacosNamingClient;
const express = require('express')
const logger = console;
const app = express()

const port = 8096

const client = new NacosNamingClient({
    logger,
    serverList: '10.19.95.31:8848', // nacos 服务端的地址
    namespace: 'c6312e73-f0af-4604-9d31-2cac9ac09f33',// nacos 命名空间
});

// register
client.ready().then(()=>{
    const serviceName = 'nodejs-provider';//服务名
    client.registerInstance(serviceName, {
        ip: '127.0.0.1',
        port: port,
    });
});

// provider
app.get('/nodejs/:who', (req, res) => {
    const content = `from ${req.params.who} to nodejs`
    console.log(content)
    res.send(content)
})

// consumer
// ...

app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
})
